import {
  ACCOUNT_CREATE,
  ACCOUNT_DELETE,
  ACCOUNT_UPDATE,
  ACCOUNT_SELECT,
  ACCOUNT_LIST
} from '../actions/s3account';

export default function s3account(
  state = {
    targetAccount: null,
    currentAccount: {
      name: '',
      id: '',
      accessKey: '',
      secretKey: '',
      region: ''
    },
    accounts: [],
    currentId: ''
  },
  action
) {
  switch (action.type) {
    case ACCOUNT_CREATE:
      return {
        ...state,
        targetAccount: action.payload.account
      };
    case ACCOUNT_DELETE:
      return {
        ...state,
        targetAccount: action.payload.account
      };
    case ACCOUNT_UPDATE:
      return {
        ...state,
        targetAccount: action.payload.account
      };
    case ACCOUNT_SELECT:
      return {
        ...state,
        targetAccount: action.payload.account,
        currentAccount: action.payload.account
      };
    case ACCOUNT_LIST:
      return {
        ...state,
        accounts: action.payload.accounts,
        currentId: action.payload.currentId
      };
    default:
      return state;
  }
}
